Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pre-fetching in map() and gen() #521

Merged
merged 4 commits into from
Nov 20, 2024
Merged

Implement pre-fetching in map() and gen() #521

merged 4 commits into from
Nov 20, 2024

Conversation

rlamy
Copy link
Contributor

@rlamy rlamy commented Oct 18, 2024

This adds a prefetch setting which enables async downloading of objects to the cache before running a generator or mapper UDF (see #40). The default is to use 2 workers, but it can be disabled using .setting(prefetch=0). Note that it has no effect if caching isn't enabled (caching is disabled by default).

In order for this to work, AbstractWarehouse.dataset_select_paginated() is now required to be thread-safe, so query result pages are now buffered as a list in that function.

Copy link

cloudflare-workers-and-pages bot commented Oct 18, 2024

Deploying datachain-documentation with  Cloudflare Pages  Cloudflare Pages

Latest commit: b54545e
Status: ✅  Deploy successful!
Preview URL: https://8858a811.datachain-documentation.pages.dev
Branch Preview URL: https://issue-40.datachain-documentation.pages.dev

View logs

Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 95.83333% with 3 lines in your changes missing coverage. Please review.

Project coverage is 88.04%. Comparing base (a9a0649) to head (b54545e).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/datachain/lib/dc.py 60.00% 1 Missing and 1 partial ⚠️
src/datachain/lib/udf.py 96.55% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #521      +/-   ##
==========================================
+ Coverage   87.92%   88.04%   +0.11%     
==========================================
  Files         102      102              
  Lines       10044    10085      +41     
  Branches     1363     1373      +10     
==========================================
+ Hits         8831     8879      +48     
+ Misses        871      865       -6     
+ Partials      342      341       -1     
Flag Coverage Δ
datachain 87.98% <95.83%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@@ -325,6 +325,7 @@ def settings(
parallel=None,
workers=None,
min_task_size=None,
prefetch: Optional[int] = None,
Copy link
Member

@shcheklein shcheklein Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: why int? let's update the docs here (do we have some CI to detect these discrepancies btw (missing docs) cc @skshetry )

Copy link
Member

@shcheklein shcheklein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. A few question.

One more general question.

Does this implementation mean that we now won't start (at least the very first row) UDF until file is fetched? Before it was doing this "on-demand" I guess - when file is needed. I wonder how big of an issue it can be in certain scenarios (and especially if we decide to do prefetch for batches (agg, batch mapper)).

@rlamy
Copy link
Contributor Author

rlamy commented Oct 29, 2024

Does this implementation mean that we now won't start (at least the very first row) UDF until file is fetched? Before it was doing this "on-demand" I guess - when file is needed. I wonder how big of an issue it can be in certain scenarios (and especially if we decide to do prefetch for batches (agg, batch mapper)).

Yes, the File object is only passed to the UDF once prefetching is complete, but note that in this PR you need to specify cache=True to activate prefetching, which you probably wouldn't do in cases where prefetching is suboptimal.

@skshetry skshetry merged commit 21857af into main Nov 20, 2024
38 checks passed
@skshetry skshetry deleted the issue-40 branch November 20, 2024 05:33
Comment on lines +235 to +236
# Ensure we're using a thread-local connection
with self.clone() as wh:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this clone() should be outside the loop? Otherwise, we'll not be reusing the connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants